package net.openl10n.trxml;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintStream;
import java.io.Reader;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.codehaus.stax2.XMLInputFactory2;
import org.codehaus.stax2.XMLStreamReader2;


public class TestCase {

	public static final Set<String> singleTags = new HashSet<String>(Arrays.asList(
			"beginpage","imagedata", "colspec", "spanspec",
	        "anchor", "xref", "area",
	        "footnoteref", "void", "inlinegraphic",
	        "glosssee", "graphic", "xi:include"
	        )); 
	
	public static final Set<String> cuttingTags = new HashSet<String>(Arrays.asList(
			"bridgehead", "trans_comment", "para", "title", "term",
		         "entry", "contrib", "keyword", "example",
		         "note", "footnote", "caution",
		         "informalexample", "remark", "comment",
		         "imageobject", "varlistentry", "thead",
		         "tbody", "tgroup", "row", "screenshot", "screeninfo",
		         "variablelist", "step", "procedure",
		         "step", "holder", "listitem", "important",
		         "author", "itemizedlist", "orderedlist",
		         "caption", "textobject", "mediaobject",
		         "tip", "glossdef", "inlinemediaobject",
		         "simplelist", "member", "glossentry",
		"areaspec", "corpauthor", "indexterm",
		         "calloutlist", "callout", "subtitle",
		"table", "part", "xi:fallback", "primary",
		         "secondary", "chapter", "sect1", "sect2",
		         "figure", "abstract", "sect3", "sect", "sect4",
		         "warning", "preface", "authorgroup", "keywordset",
		"informaltable", "qandaentry", "question", "answer",
		"othercredit", "affiliation", "qandaset",
		"cmdsynopsis", "funcsynopsis", "funcsynopsisinfo" ,
		"epigraph", "attribution", "glossary", "chapterinfo",
		"glossdiv", "blockingquote", "simplesect", "section",
		"qandadiv", "refsect1", "refmeta", "formalpara",
		"refentry", "refnamediv", "refpurpose", "refentrytitle",
		         "refmiscinfo", "refsect2", "refsect3", "refsect1info",
		         "refsect2info", "refsect3info", "refsection", "refsectioninfo",
		         "refsynopsisdiv", "refsysnopsisdivinfo", "remark",
		         "revdescription", "glossentry", "partinfo",
		"segmentedlist", "segtitle", "seg", "seglistitem", "screenco"
	));
	
	public static final Set<String> literalTags = new HashSet<String>(Arrays.asList(
			"literallayout", "synopsis", "screen","programlisting"));	
	
	public TestCase() {
		XMLInputFactory2 factory =(XMLInputFactory2) XMLInputFactory2.newInstance();
		TrXMLReaderFactory trFactory = TrXMLReaderFactory.newInstance();

		factory.setProperty(XMLInputFactory2.P_REPORT_PROLOG_WHITESPACE, true);
		factory.setProperty(XMLInputFactory2.IS_REPLACING_ENTITY_REFERENCES, false);
		factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
		factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
//		factory.setProperty(XMLInputFactory., value)

		TrXMLStreamReader streamReader;
		try {
			
			streamReader = trFactory.wrap(
					(XMLStreamReader2) factory.createXMLStreamReader(
				    new FileReader(
				    		"/home/asgeirf/projects/gitsvn/Deployment_Guide/en-US/Bind.xml")));

			streamReader.addTranslatableElement("para");
			PrintStream s = System.out;
			while(streamReader.hasNext()){
			    streamReader.next();
			    switch(streamReader.getEventType()){
			    case XMLStreamReader2.ATTRIBUTE:
			    	s.println("att");
			    	break;
			    case XMLStreamReader.CDATA:
			    	s.println("cdata");
			    	break;
			    case XMLStreamReader.CHARACTERS:
			    	s.println("chars");
			    	break;
			    case XMLStreamReader.COMMENT:
			    	s.println("comment");
			    	break;
			    case XMLStreamReader.DTD:
			    	s.println("dtd");
			    	s.println(streamReader.getDTDInfo().getDTDPublicId());
			    	s.println(streamReader.getText());
			    	break;
			    case XMLStreamReader.END_DOCUMENT:
			    	s.println("end-doc");
			    	break;
			    case XMLStreamReader.END_ELEMENT:
			    	s.println("end-element");
			    	break;
			    case XMLStreamReader.ENTITY_DECLARATION:
			    	s.println("ent_decl");
			    	break;
			    case XMLStreamReader.ENTITY_REFERENCE:
			    	s.println("ent_ref: " + streamReader.getLocalName());
			    	break;
			    case XMLStreamReader.NAMESPACE:
			    	s.println("ns");
			    	break;
			    case XMLStreamReader.NOTATION_DECLARATION:
			    	s.println("notation_decl");
			    	break;
			    case XMLStreamReader.PROCESSING_INSTRUCTION:
			    	s.println("pi");
			    	break;
			    case XMLStreamReader.SPACE:
			    	s.println("space");
			    	break;
			    case XMLStreamReader.START_DOCUMENT:
			    	s.println("start-doc");
			    	break;
			    case XMLStreamReader.START_ELEMENT:
			    	switch(streamReader.getTranslatableType()){
			    	case TrXMLStreamReader.CONTENT_NOT_TRANSLATABLE:
			    		s.print("NT: ");
			    		break;
			    	case TrXMLStreamReader.CONTEXT_TRANSLATABLE_BLOCK:
			    		s.print(" T: ");
			    		break;
			    	}
		    		s.print(streamReader.getName() + "\n");
		    		break;
			    	
			    }
			}
		
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XMLStreamException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			    
	}
	
	public static void main(String[] args) {
		new TestCase();
	}
	
}
